<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class CommonController extends Controller
{
    //图片上传
    public function upload()
    {
        //测试路由
//        echo 'upload';
        //看看上传后是什么
//        $input = Input::all();
//        dd($input);
        //用get()方法获取Filedate
//        $file = Input::file('Filedata');
//        dd($file);
        $file = Input::file('Filedata');
        if($file -> isValid()){
            //检验一下上传的文件是否有效.

            $entension = $file -> getClientOriginalExtension(); //上传文件的后缀.
            $newName = date('YmdHis').mt_rand(100,999).'.'.$entension;//新文件名
            $path = $file -> move(base_path().'/uploads',$newName);//base_path()根目录，完整路径
//            echo $path;
            $filepath = 'uploads/'.$newName;//文件路径

            return $filepath;
        }
    }
}
